package com.xingkeduo.business.order.controller;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.business.order.service.*;
import com.xingkeduo.dto.param.*;
import com.xingkeduo.dto.transter.Comment;
import com.xingkeduo.dto.transter.activitycardlist.ActivityCardListParameterDto;
import com.xingkeduo.dto.transter.activitycouponlist.ActivityCouponListParameterDto;
import com.xingkeduo.dto.transter.activitystorelist.ActivityStoreListParameterDto;
import com.xingkeduo.dto.transter.appointment.AppointmentSubmit;
import com.xingkeduo.dto.transter.appointment.CheckNewUserCouponDto;
import com.xingkeduo.dto.transter.carddetail.CardDetailParameterDto;
import com.xingkeduo.dto.transter.cardlist.CardListParameterDto;
import com.xingkeduo.dto.transter.comment.CommentSubmit;
import com.xingkeduo.dto.transter.commentfinish.CommentFinishParameterDto;
import com.xingkeduo.dto.transter.commentfinish.Commentfinish;
import com.xingkeduo.dto.transter.coupondetail.CouponDetailParameterDto;
import com.xingkeduo.dto.transter.couponlist.CouponListParameterDto;
import com.xingkeduo.dto.transter.evaluation.JsonRootBean;
import com.xingkeduo.dto.transter.giftbagdetail.GiftBagDetailParameterDto;
import com.xingkeduo.dto.transter.hairstyle.CommentHairStyle;
import com.xingkeduo.dto.transter.hairstyleDetails.HairstyleDetail;
import com.xingkeduo.dto.transter.hairstyleSelected.HairstyleSelect;
import com.xingkeduo.dto.transter.marketingbagdetail.MarketingBagDetailParameterDto;
import com.xingkeduo.dto.transter.marketingbagreceive.MarketingBagReceiveParameterDto;
import com.xingkeduo.dto.transter.marketingdetail.MarketingDetailParameterDto;
import com.xingkeduo.dto.transter.marketingreceive.MarketingReceiveParameterDto;
import com.xingkeduo.dto.transter.marketingsuccessdetail.MarketingSuccessDetailParameterDto;
import com.xingkeduo.dto.transter.order.OrderResponseDto;
import com.xingkeduo.dto.transter.orderdetail.OrderDetail;
import com.xingkeduo.dto.transter.orderserviec.OrderServiceType;
import com.xingkeduo.dto.transter.refund.Refund;
import com.xingkeduo.dto.transter.refunddetail.RefundDetail;
import com.xingkeduo.dto.transter.shopDistance.DistanceReturn;
import com.xingkeduo.dto.transter.storelist.StoreListParameterDto;
import com.xingkeduo.dto.transter.upload.ImgResult;
import com.xingkeduo.dto.transter.verification.VerificationCode;
import com.xingkeduo.json.BaseDTOJTO;
import com.xingkeduo.utils.QRCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;


@RestController
@RequestMapping("/mobile")
@Slf4j
public class TransterController {

    @Resource
    private CommentsService commentsService;
    @Resource
    private ConsumerService consumerService;
    @Resource
    private OperateService operateService;
    @Resource
    private MarketingService marketingService;
    @Resource
    private ActivityService activityService;

    @Resource
    private CheckService checkService;


    @RequestMapping("/error")
    public ObjectNode error(){
        return BaseDTOJTO.error();
    }

    @RequestMapping("/update")
    public ObjectNode update(){
        return BaseDTOJTO.serviceUpdate();
    }

    /**
     * 微信js授权接口 
     * @param consumerPrivateParameterDto
     * @return
     * @author : gaozifeng
     * ObjectNode
     */
    @RequestMapping("/wechat_config")
    public ObjectNode wechat_config(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.jsApi(consumerPrivateParameterDto);
    }

    /**
     * code授权 小程序用户授权
     *
     * @param consumerPrivateParameterDto:
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/5/7 17:46
     */
    @GetMapping("/code")
    public ObjectNode code(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.code(consumerPrivateParameterDto);
    }

    /**
     * 拉取用户信息
     *
     * @param consumerPrivateParameterDto:
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/5/7 17:46
     */
    @GetMapping("/get_user_info")
    public ObjectNode get_user_info(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.get_user_info(consumerPrivateParameterDto);
    }

    /**
     * 获取用户信息
     *
     * @param distanceQueryParameterDto
     * @return
     */
    @GetMapping("/user")
    public String user(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.user(consumerPrivateParameterDto);
    }



    /**
     * 更改绑定手机号  pantong  2019年5月15日下午2:42:30
     *
     * @param consumerPrivateParameterDto
     * @return String
     */
    @GetMapping("/ajax_update_mobile")
    public String ajax_update_mobile(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.ajax_update_mobile(consumerPrivateParameterDto);
    }

    /**
     * 获取用户标签设置想
     *
     * @param distanceQueryParameterDto
     * @return
     */
    @GetMapping("/revise_set")
    public String revise_set(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.revise_set(consumerPrivateParameterDto);
    }


    /**
     * 获取店铺列表
     *
     * @param shopsParameterDto
     * @return
     */
    @GetMapping("/store_list")
    public String store_list(ShopsParameterDto shopsParameterDto) {
        return operateService.store_list(shopsParameterDto);
    }

    /**
     * 获取店铺详情
     *
     * @param shopsParameterDto
     * @return
     */
    @GetMapping("/store_detail")
    public String store_detail(ShopsParameterDto shopsParameterDto) {
        return operateService.store_detail(shopsParameterDto);
    }

    /**
     * 修改手机号发送验证码
     *
     * @param distanceQueryParameterDto
     * @return
     */
    @GetMapping("/ajax_send_sms_vertify_code")
    public String ajax_send_sms_vertify_code(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.ajax_send_sms_vertify_code(consumerPrivateParameterDto);
    }

    /**
     * 获取发型列表
     *
     * @param
     * @return
     */
    @GetMapping("/hairstyle_list")
    public HairstyleSelect getHairstyleList(HairstyleSelectedParameterDto hairstyleSelectedParameterDto) {
        HairstyleSelect hairstyleSelect = operateService.getHairstyleList(hairstyleSelectedParameterDto);
        return hairstyleSelect;
    }

    /**
     * 获取发型详情
     *
     * @param
     * @return
     */
    @GetMapping("/hairstyle_detail")
    public HairstyleDetail getHairstyleDetail(HairstyleDetailParameterDto hairstyleDetailParameterDto) {
        HairstyleDetail hairstyleDetail = operateService.getHairstyleDetail(hairstyleDetailParameterDto);
        return hairstyleDetail;
    }

    /**
     * 查询work
     *
     * @param
     * @return
     */
    @GetMapping("/update_work")
    public String update_work(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.update_work(consumerPrivateParameterDto);
    }

    /**
     * 修改work
     *
     * @param
     * @return
     */
    @GetMapping("/ajax_update_work")
    public String ajax_update_work(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.ajax_update_work(consumerPrivateParameterDto);
    }

    /**
     * 查询sex
     *
     * @param
     * @return
     */
    @GetMapping("/update_sex")
    public String update_sex(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.update_sex(consumerPrivateParameterDto);
    }

    /**
     * 修改sex
     *
     * @param
     * @return
     */
    @GetMapping("/ajax_update_sex")
    public String ajax_update_sex(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.ajax_update_sex(consumerPrivateParameterDto);
    }

    /**
     * 查询age
     *
     * @param
     * @return
     */
    @GetMapping("/update_age")
    public String update_age(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.update_age(consumerPrivateParameterDto);
    }

    /**
     * 修改age
     *
     * @param
     * @return
     */
    @GetMapping("/ajax_update_age")
    public String ajax_update_age(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
        return consumerService.ajax_update_age(consumerPrivateParameterDto);
    }

    /**
     * 查询风格定位
     *
     * @param
     * @return
     */
    @GetMapping("/update_style")
    public String update_style(ConsumerStyleParameterDto consumerStyleParameterDto) {
        return consumerService.update_style(consumerStyleParameterDto);
    }

    /**
     * 修改风格定位
     *
     * @param
     * @return
     */
    @GetMapping("/ajax_update_style")
    public String ajax_update_style(ConsumerStyleParameterDto consumerStyleParameterDto) {
        return consumerService.ajax_update_style(consumerStyleParameterDto);
    }


    /**
     * 查询到店距离
     *
     * @param
     * @return
     */
    @GetMapping("/update_care")
    public String update_care(DistanceQueryParameterDto distanceQueryParameterDto) {
        return consumerService.update_care(distanceQueryParameterDto);
    }

    /**
     * 修改到店距离
     *
     * @param distanceQueryParameterDto
     * @return
     */
    @GetMapping("/ajax_update_care")
    public String ajax_update_care(DistanceQueryParameterDto distanceQueryParameterDto) {
        return consumerService.ajax_update_care(distanceQueryParameterDto);
    }


    /**
     * 查询历史/门店评价接口
     *
     * @param commentList
     * @return
     */
    @GetMapping("/comment_list")
    public Comment getCommensByUserId(CommentList commentList) {
        Comment comment = commentsService.getCommensByUserId(commentList);
        return comment;
    }

    /**
     * 获取评价等级的所有标签
     *
     * @param commentCreateDto
     * @return
     */
    @GetMapping("/comment_create")
    public JsonRootBean getCommensLabels(CommentCreateDto commentCreateDto) {
        JsonRootBean jsonRootBean = commentsService.getCommensLabels(commentCreateDto);
        return jsonRootBean;
    }


    /**
     * 获取验证码
     *
     * @param refreshCodeDto
     * @return
     */
    @GetMapping("/refresh_code")
    public VerificationCode getRefreshCode(RefreshCodeDto refreshCodeDto) {
        VerificationCode verificationCode = commentsService.getRefreshCodeDto(refreshCodeDto);
        return verificationCode;
    }

    /**
     * 获取订单列表  Todo 返回值待修改
     *
     * @param orderParameterDto
     * @return
     */
    @GetMapping("/order_list")
    public OrderResponseDto userQuery(OrderParameterDto orderParameterDto) {
        OrderResponseDto orderResponseDto = commentsService.userQuery(orderParameterDto);
        return orderResponseDto;
    }


    /**
     * 获取订单详情     Todo 返回值待修改
     *
     * @param orderDetailParameterDto
     * @return
     */
    @GetMapping("/order_detail")
    public OrderDetail userQueryDetail(OrderDetailParameterDto orderDetailParameterDto) {
        OrderDetail orderDetail = commentsService.userQueryDetail(orderDetailParameterDto);
        return orderDetail;
    }

    /**
     * 改变发型
     *
     * @param hairStyleParameterDto
     * @return
     */
    @GetMapping("/change_hairstyle")
    public CommentHairStyle hair(HairStyleParameterDto hairStyleParameterDto) {
        CommentHairStyle commentHairStyle = commentsService.hair(hairStyleParameterDto);
        return commentHairStyle;
    }


    /**
     * 退款订单详情
     *
     * @param refundDetailParameterDto
     * @return
     */
    @GetMapping("/refund_detail")
    public RefundDetail refundDetail(RefundDetailParameterDto refundDetailParameterDto) {
        RefundDetail refundDetail = commentsService.refundDetail(refundDetailParameterDto);
        return refundDetail;
    }


    /**
     * 评价提交
     *
     * @param commentSubmitParameterDto
     * @return
     */
    @GetMapping("/comment_submit")
    public CommentSubmit commentSubmit(CommentSubmitParameterDto commentSubmitParameterDto) {
        CommentSubmit commentSubmit = commentsService.commentSubmit(commentSubmitParameterDto);
        return commentSubmit;
    }


    /**
     * 订单退款
     *
     * @param orderRefundDto
     * @return
     */
    @GetMapping("/refund")
    public Refund refund(OrderRefundDto orderRefundDto) {
        Refund refund = commentsService.refund(orderRefundDto);
        return refund;
    }


    /**
     * 评价完成
     *
     * @param commentFinishParameterDto
     * @return
     */
    @GetMapping("/comment_finish")
    public Commentfinish commentFinish(CommentFinishParameterDto commentFinishParameterDto) {
        Commentfinish commentfinish = commentsService.commentFinish(commentFinishParameterDto);
        return commentfinish;
    }


    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    @PostMapping("/comment_photo_upload")
    public ImgResult uploadComment(@RequestPart("file") MultipartFile file) {
        return commentsService.uploadComment(file);
    }


    /**
     * 图片上传
     *
     * @param file
     * @return
     */
    @GetMapping("/card_list")
    public String card_list(CardListParameterDto cardParameterDto) {
        log.info("调用 card_list,请求值:cardParameterDto,{} ", cardParameterDto.covert());
        return marketingService.card_list(cardParameterDto);
    }

    @GetMapping("/get_card_detail")
    public String get_card_detail(CardDetailParameterDto cardDetailParameterDto) {
        log.info("调用 get_card_detail,请求值:cardDetailParameterDto,{} ", cardDetailParameterDto.covert());
        return marketingService.get_card_detail(cardDetailParameterDto);
    }

    @GetMapping("/coupon_list")
    public String coupon_list(CouponListParameterDto couponListParameterDto) {
        log.info("调用 coupon_list,请求值:cardDetailParameterDto,{} ", couponListParameterDto.covert());
        return marketingService.coupon_list(couponListParameterDto);
    }

    @GetMapping("/coupon_detail")
    public String coupon_detail(CouponDetailParameterDto couponDetailParameterDto) {
        log.info("调用 coupon_detail,请求值:couponDetailParameterDto,{} ", couponDetailParameterDto.covert());
        return marketingService.coupon_detail(couponDetailParameterDto);
    }

    @GetMapping("/user_gift_bag_detail")
    public String user_gift_bag_detail(GiftBagDetailParameterDto giftBagDetailParameterDto) {
        return marketingService.user_gift_bag_detail(giftBagDetailParameterDto);
    }

    @GetMapping("/user_store_activity")
    public String user_store_activity(ActivityStoreListParameterDto activityStoreListParameterDto) {
        return activityService.acitivty_store_list(activityStoreListParameterDto);
    }

    @GetMapping("/use_card")
    public String user_card_activity(ActivityCardListParameterDto activityCardListParameterDto) {
        log.info("调用 use_card,请求值:activityCardListParameterDto,{} ", activityCardListParameterDto.covert());
        return activityService.acitivty_card_list(activityCardListParameterDto);
    }

    @GetMapping("/use_coupon")
    public String user_coupon_activity(ActivityCouponListParameterDto activityCouponListParameterDto) {
        log.info("调用 use_coupon,请求值:activityCouponListParameterDto,{} ", activityCouponListParameterDto.covert());
        return activityService.acitivty_coupon_list(activityCouponListParameterDto);
    }

    @GetMapping("/marketing_detail")
    public String marketing_detail(MarketingDetailParameterDto marketingDetailParameterDto) {
        log.info("调用 marketing_detail,请求值:marketingDetailParameterDto,{} ", marketingDetailParameterDto.covert());
        return marketingService.marketing_detail(marketingDetailParameterDto);
    }

    @GetMapping("/marketing_bag_detail")
    public String marketing_bag_detail(MarketingBagDetailParameterDto marketingBagDetailParameterDto) {
        log.info("调用 marketing_bag_detail,请求值:marketingBagDetailParameterDto,{} ", marketingBagDetailParameterDto.covert());
        return marketingService.marketing_bag_detail(marketingBagDetailParameterDto);
    }

    @GetMapping("/marketing_store_list")
    public String marketing_store_list(StoreListParameterDto storeListParameterDto) {
        log.info("调用 marketing_store_list,请求值:storeListParameterDto,{} ", storeListParameterDto.covert());
        return marketingService.marketing_store_list(storeListParameterDto);
    }
    @GetMapping("/marketing_receive")
    public String marketing_receive(MarketingReceiveParameterDto marketingReceiveParameterDto) {
        log.info("调用 marketing_receive,请求值:storeListParameterDto,{} ", marketingReceiveParameterDto.covert());
        return marketingService.marketing_receive(marketingReceiveParameterDto);
    }
    @GetMapping("/marketing_bag_receive")
    public String marketing_bag_receive(MarketingBagReceiveParameterDto marketingBagReceiveParameterDto) {
        log.info("调用 marketing_bag_receive,请求值:storeListParameterDto,{} ", marketingBagReceiveParameterDto.covert());
        return marketingService.marketing_bag_receive(marketingBagReceiveParameterDto);
    }
    
    @GetMapping("/marketing_success_detail")
    public String marketing_success_detail(MarketingSuccessDetailParameterDto marketingSuccessDetailParameterDto) {
        log.info("调用 marketing_detail,请求值:marketingSuccessDetailParameterDto,{} ", marketingSuccessDetailParameterDto.covert());
        return marketingService.marketing_success_detail(marketingSuccessDetailParameterDto);
    }
    /**
     * 获取二维码
     *
     * @param response
     * @param data_url
     */
    @RequestMapping(value = "/qrcode")
    public void qrcode(HttpServletResponse response, String data_url, String storeId) {
        BufferedImage bufferedImage = QRCodeUtils.genGR(data_url);

        try {
            ImageIO.write(bufferedImage, "png", response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    /**
     * 获取订单类型
     *
     * @param store_id
     * @param order_no
     * @return
     */
    @RequestMapping(value = "/get_order_serviec_type")
    public OrderServiceType getOrderService(String store_id, String order_no) {
        return commentsService.getOrderService(store_id, order_no);
    }


    /**
     * @return com.xingkeduo.dto.transter.appointment.AppointmentSubmit
     * @description 用户自主兑换 http://wiki.xingkeduo.com/pages/viewpage.action?pageId=1410023
     * @Author 情绪极其不稳定的Shadow
     * @Param [checkNewUserCouponDto]
     **/
    @GetMapping("/self_add_order")
    public AppointmentSubmit selfAddOrder(CheckNewUserCouponDto checkNewUserCouponDto) {
        log.info("调用 self_add_order, 请求值:checkNewUserCouponDto--->>>,{}", checkNewUserCouponDto.toString());
        return checkService.selfAddOrder(checkNewUserCouponDto);
    }

    /**
     * @return com.xingkeduo.dto.transter.appointment.AppointmentSubmit
     * @description 顾客自助核销 + 口碑核销 + 美团核销 http://wiki.xingkeduo.com/pages/viewpage.action?pageId=1410025
     * @Author 情绪极其不稳定的Shadow
     * @Param [checkNewUserCouponDto]
     **/
    @GetMapping("/customer_check_ticket_doself")
    public AppointmentSubmit customerCheckTicketDoself(CheckNewUserCouponDto checkNewUserCouponDto) {
        log.info("调用 customer_check_ticket_doself, 请求值:checkNewUserCouponDto--->>>,{}", checkNewUserCouponDto.toString());
        AppointmentSubmit appointmentSubmit = checkService.channel(checkNewUserCouponDto);
        return appointmentSubmit;
    }

    @GetMapping("/get_coupon_bag_info")
    public AppointmentSubmit getCouponBagInfo(CheckNewUserCouponDto checkNewUserCouponDto) {
        log.info("调用 get_coupon_bag_info, 请求值:checkNewUserCouponDto--->>>,{}", checkNewUserCouponDto.toString());
        AppointmentSubmit appointmentSubmit = checkService.getCouponBagInfo(checkNewUserCouponDto);
        return appointmentSubmit;
    }

    /**
     * 根据经纬度查询最近店铺ID
     * @param latitude
     * @param longitude
     * @return
     */
    @GetMapping("/get_store_by_gps")
    public DistanceReturn getStoreByGps(Double latitude , Double longitude,Long f_user_id) {

        DistanceReturn longitudeAndLatitudeShopInfo = operateService.getLongitudeAndLatitudeShopInfo(latitude, longitude,f_user_id);
        return longitudeAndLatitudeShopInfo;
    }
}
